var progress = $("input[name=progress]").val();
var subscribeID = $("input[name=detailSubscribeID]").val();
var app = angular.module('subscribeDetailApp', [ 'ngRoute' ]);
app.config([ '$routeProvider', function($routeProvider) {
	$routeProvider.when('/', {
		templateUrl : 'subscribe_detail1.html'
	}).when('/progress', {
		templateUrl : (progress == '0' ? 'subscribe_detail2.html' : 'subscribe_detail_done.html')
	}).when('/fee', {
		templateUrl : 'subscribe_detail3.html'
	}).otherwise({
		redirectTo : '/'
	});
} ]);
app.controller('subscribeDetailController', function($scope, $http) {
	
	$scope.titleClass = [ {
		"li" : "w33 rline",
		"span" : "tabfouse"
	}, {
		"li" : "w33",
		"span" : ""
	}, {
		"li" : "w33",
		"span" : ""
	} ];

	$scope.statusLabel = [ "进行中", "已完成" ];
	$scope.subscribeList = [];
	
	var query = function(){

		$http({
	        method: 'POST',
	        url: '../query.do',
	        data: { "queryID": "instrument.S002", "condition": [subscribeID] },  
	        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },  
           	transformRequest: function(obj) {
            	var str = [];
            	for (var s in obj) {
                	str.push(encodeURIComponent(s) + "=" + encodeURIComponent(obj[s]));  
            	}
            	return str.join("&");  
           	}
	    }).then(
	    	function successCallback(response) {
	    		$scope.subscribeList = response.data.dataList;
	    		console.log(response.data);
	        }, function errorCallback(response) {
	        	console.log(response);
	    });
	};

	$scope.titleClick = function(status) {

		if (status == 0) {
			$scope.titleClass = [ {
				"li" : "w33 rline",
				"span" : "tabfouse"
			}, {
				"li" : "w33",
				"span" : ""
			}, {
				"li" : "w33",
				"span" : ""
			} ];
		} else if (status == 1) {
			$scope.titleClass = [ {
				"li" : "w33",
				"span" : ""
			}, {
				"li" : "w33 rline",
				"span" : "tabfouse"
			}, {
				"li" : "w33",
				"span" : ""
			} ];
		} else if (status == 2) {
			$scope.titleClass = [ {
				"li" : "w33",
				"span" : ""
			}, {
				"li" : "w33",
				"span" : ""
			}, {
				"li" : "w33 rline",
				"span" : "tabfouse"
			} ];
		}
	};
	
	query();
	$scope.titleClick(0);
});
/*
//页面返回刷新
pushHistory();
setTimeout(function () {
 window.addEventListener("popstate", function (e) {
     window.location.href = 'order_list.html';
 }, false);
}, 300);
function pushHistory() {
 var state = {
     title: "title",
     url: "#"
 };
 window.history.pushState(state, "title", "#");
}
*/